//
//  QSAdaptedTool.m
//  myTest
//
//  Created by Song on 2018/11/20.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "QSAdaptedTool.h"

@implementation QSAdaptedTool
/**
 安全区域
 */
+ (UIEdgeInsets)safaAreaInset
{
    if (@available(iOS 11.0, *)) {
        return UIApplication.sharedApplication.delegate.window.safeAreaInsets;
    } else {
        return UIEdgeInsetsZero;
    }
}

/**
 是否是刘海屏
 */
+ (BOOL)isBangScreen
{
    UIEdgeInsets safeInset = UIEdgeInsetsZero;
    
    if (@available(iOS 11.0, *)) {
        safeInset = UIApplication.sharedApplication.delegate.window.safeAreaInsets;
    }
    return safeInset.top > 20.0;
}

/**
 适配宽度
 */
+ (CGFloat)adaptedWidth:(CGFloat)value
{
    CGFloat ratio = 1.0;
    if ([self isBangScreen]) {
        // 刘海屏，以iPhone X 为准
        ratio = kScreenWidth / 414.0;
    } else {
        // 普通屏，以iphone6 为准
        ratio = kScreenWidth / 375.0;
    }
    
    return ceilf(value * ratio);
}

/**
 适配高度
 */
+ (CGFloat)adaptedHeight:(CGFloat)value
{
    CGFloat ratio = 1.0;
    if ([self isBangScreen]) {
        // 刘海屏，以iPhone X 为准
        ratio = kScreenHeight / 896.0;
    } else {
        // 普通屏，以iphone6 为准
        ratio = kScreenHeight / 667.0;
    }
    
    return ceilf(value * ratio);
}
@end
